<?php

$dbc = new PDO('mysql:host=localhost;dbname=Mentor', 'DB Admin', 'MarshyHaka1982');
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Database connection established";

if (isset($_REQUEST['doSave'])) {
    // Fire up your database and do something like
    // INSERT INTO db SET fldSchool = '".addslashes($_REQUEST['School'])."'
    //echo 'testing';
	try {
	    $r = $dbc->Query("INSERT INTO test.mentors SET 
			 mentorFirstName = '".addslashes($_REQUEST['FirstName'])."'
			,mentorLastName = '".addslashes($_REQUEST['Surname'])."'
		");
	} catch (PDOException $e) {
	    echo "Query failed<br />";
	    echo $e->getMessage();
	    // Crash should exit
	}    if ($_REQUEST['School'] == '_init_') {
        $_REQUEST['School'] = 'lsakjfd';
        // or tell user it is an error.
    }
    
    // If all data OK and data inserted into db ok, then maybe go to some other screen? or show this screen with 'success' message and blank stuff out.
    // If user errors, show some kind of message
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>Offline Mentor Database Login</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <style type="text/css">
  body {
	background-color: #CFF;
}
  </style>
  </head>
<body>

    <pre>
<?php

    echo print_r($_REQUEST);

?>

<form name=DBLogin method=get action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h1 align="center"><strong>Offline Mentor Database - Login</strong></h1>
<table align='center'>

<tr><td>Username:</td><td><input name="UserID" type="text" value="" maxlength="15"></td></tr>

<tr><td>Password</td><td><input name="userpass" type="password" value="" maxlength="25"></td></tr>

<tr><td></td><td><input name="doSubmit" value="Login" type="submit"></td></tr>
</table> 
 </form>


